<%@ page import="java.util.Objects" %>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>输入更新</title>
</head>
<body>
<h2>输入更新</h2>
<%
    request.setCharacterEncoding("utf-8");

    String username="root";
    String pwd="pengfei";
    String driverName="com.mysql.jdbc.Driver";
    String dbName="student";
    String url="jdbc:mysql://127.0.0.1:3306/"+dbName+"?user="+username+"&password="+pwd+"&useUnicode=true&characterEncoding=UTF-8";
    String sql="";

    int id = 0;
    String name=null;
    String sex=null;
    String age=null;
    String weight=null;
    String height=null;

    Connection connection = null;
    ResultSet rs = null;
    PreparedStatement st = null;
    try {
        Class.forName(driverName);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    try {
        connection= DriverManager.getConnection(url);
        if(!request.getParameter("id").equals("")) {
            id = Integer.parseInt(request.getParameter("id"));
            session.setAttribute("idselect",id);
            sql="select * from stu_info where id="+id;
        }
        st=connection.prepareStatement(sql);
        rs=st.executeQuery(sql);
    } catch (SQLException e) {
        e.printStackTrace();
    }

    assert rs != null;
    try {
    if(rs.next()) {
        name = rs.getString("name");
        sex = rs.getString("sex");
        age = rs.getString("age");
        weight = rs.getString("weight");
        height = rs.getString("height");
    }
    }catch (Exception e){
        e.printStackTrace();
    }

%>
<form name="from3" action="shujuupdate_process_edit.jsp" method="post">
<table>
    <tr><td>学号</td><td><input type="text" name="id" value=<%=id%>></td></tr>
    <tr><td>姓名</td><td><input type="text" name="name" value=<%=name%>></td></tr>
    <tr><td>性别</td><td><input type="text" name="sex" value=<%=sex%>></td></tr>
    <tr><td>年龄</td><td><input type="text" name="age" value=<%=age%>></td></tr>
    <tr><td>体重</td><td><input type="text" name="weight" value=<%=weight%>></td></tr>
    <tr><td>身高</td><td><input type="text" name="height" value=<%=height%>></td></tr>

    <%
        if(rs!=null) rs.close();
        if(st!=null) st.close();
        if(connection!=null) connection.close();
    %>
    <tr>
    <td><input type="submit" value="更新"></td>
    <td><input type="reset" value="取消"></td>
    </tr>
</table>
</form>
</body>
</html>
